<script setup name="Login">
import { reactive } from "vue";
import { useRouter } from "vue-router";
import { login } from "../api/login.js";
const router = useRouter();
const state = reactive({
  froms: {
    username: "",
    password: "",
  },
});
const onSubmit = (values) => {
  login(values)
    .then((res) => {
      sessionStorage.setItem("operateToken", res.token);
      router.push("/equipmentNumber");
    })
    .catch((err) => {
      console.log(err);
    });
};
</script>
<template>
  <div class="outer_box">
    <div class="login_class">
      <div class="titles">欢迎登陆,中检车服</div>
      <van-form @submit="onSubmit">
        <van-cell-group inset>
          <van-field
            v-model="state.froms.username"
            clearable
            name="username"
            label="用户名"
            placeholder="请填写用户名"
            :rules="[{ required: true, message: '用户名不能为空' }]"
          >
          </van-field>
          <van-field
            v-model="state.froms.password"
            clearable
            type="password"
            name="password"
            label="密码"
            placeholder="请填写密码"
            :rules="[{ required: true, message: '密码不能为空' }]"
          >
          </van-field>
        </van-cell-group>
        <p class="tips">tips:如无权限，请联系后台管理员开通</p>
        <div style="margin: 16px">
          <van-button block color="#1c4880" native-type="submit">
            确认
          </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.outer_box {
  height: calc(100vh - 100px);
  overflow: hidden;
}
.login_class {
  box-sizing: border-box;
  height: 318px;
  padding-top: 32px;
  margin: 20px;
  margin-top: 50px;
  background-color: #f2f2f2;
  border-radius: 10px;
  box-shadow: 3px 4px 6px #888888;
  .titles {
    font-size: 20px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 20px;
  }
  .tips {
    margin: 15px 0px 0px 20px;
    color: #1c4880;
  }
}
</style>
